package com.hancher.gamelife2.colockin;

import android.content.Context;
import android.graphics.Color;

import androidx.annotation.NonNull;

import com.github.gzuliyujiang.calendarpicker.core.CalendarView;
import com.github.gzuliyujiang.calendarpicker.core.ColorScheme;
import com.github.gzuliyujiang.calendarpicker.core.OnDateSelectedListener;
import com.hancher.common.javautil.DateUtil;
import com.hancher.gamelife2.R;
import com.hancher.gamelife2.databinding.DialogColockinAndTimeBinding;
import com.lxj.xpopup.core.CenterPopupView;

import java.util.Date;

/**
 * 描述 : 打卡弹窗 <br/>
 * 时间 : 2024/1/15 11:53 <br/>
 * 作者 : Hancher ytu_shaoweijie@163.com
 */
public class ColockInSignDialog extends CenterPopupView {

    private final OnSuccessClickListener listener;
    private final ColockInTypePO type;
    private DialogColockinAndTimeBinding binding;

    public Date selectDate;

    interface OnSuccessClickListener {
        void onSuccess(CharSequence description, Date selectDate);
    }


    public ColockInSignDialog(@NonNull Context context, ColockInTypePO colockInTypePO, OnSuccessClickListener listener) {
        super(context);
        this.type = colockInTypePO;
        this.listener = listener;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        binding = DialogColockinAndTimeBinding.bind(getPopupImplView());
        CalendarView calendarView = binding.calendarPickerBodyVertical;
        calendarView.enablePagerSnap();//横向滑动
        ColorScheme cs = new ColorScheme();
        cs.daySelectTextColor(Color.WHITE)
                .daySelectBackgroundColor(Color.parseColor("#4169E1"));
        calendarView.getAdapter()
                .notify(false)
                .single(true)//单选
//                                    .festivalProvider(new MyFestivalProvider())
                .colorScheme(cs)
                .intervalNotes("选择", "选择")//单选也要写两个
                .valid(DateUtil.getDateAddYear(-10), DateUtil.getDateAddYear(10))
                .range(DateUtil.getDateAddYear(-10), DateUtil.getDateAddYear(10))
                .select(new Date(), new Date())
                .refresh();
        calendarView.getAdapter().setOnCalendarSelectedListener(new OnDateSelectedListener() {
            @Override
            public void onSingleSelected(@NonNull Date date) {
                selectDate = date;
            }

            @Override
            public void onRangeSelected(@NonNull Date start, @NonNull Date end) {

            }
        });
        calendarView.getBodyView().scrollToPosition(120);
        binding.btnOk.setOnClickListener(v1 -> {
            listener.onSuccess(binding.etRemark.getText().toString(), selectDate);
            dialog.dismiss();
        });
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_colockin_and_time;
    }
}
